package com.car.rental.vehicle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.car.rental.vehicle.entity.VehicleImage;
import com.car.rental.vehicle.mapper.VehicleImageMapper;
import com.car.rental.vehicle.service.VehicleImageService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class VehicleImageServiceImpl extends ServiceImpl<VehicleImageMapper, VehicleImage> implements VehicleImageService {
    
    @Override
    public List<VehicleImage> getByVehicleId(Long vehicleId) {
        return list(new LambdaQueryWrapper<VehicleImage>()
                .eq(VehicleImage::getVehicleId, vehicleId));
    }
    
    @Override
    public Map<Long, String> getMainImageUrls(List<Long> vehicleIds) {
        LambdaQueryWrapper<VehicleImage> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(VehicleImage::getVehicleId, vehicleIds);
        
        return list(wrapper).stream()
                .collect(Collectors.toMap(
                        VehicleImage::getVehicleId,
                        VehicleImage::getUrl,
                        (v1, v2) -> v1
                ));
    }
} 